/**
 * Copyright (c) 2020 rxi
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the MIT license. See `log.c` for details.
 */

#ifndef APPS_LOG_H
#define APPS_LOG_H

#include "stm32f4xx.h"

#define LOG_VERSION "0.1.0"
#define _DEBUG_

enum LOG_LEVEL
{
    LOG_DEBUG,
    LOG_INFO,
    LOG_WARN,
    LOG_ERROR,
    LOG_FATAL
};

#ifdef _DEBUG_

#define DBG(...) log_log(LOG_DEBUG, TAG, __VA_ARGS__)
#define INFO(...) log_log(LOG_INFO, TAG, __VA_ARGS__)
#define WARN(...) log_log(LOG_WARN, TAG, __VA_ARGS__)
#define TODO(...) log_log(LOG_WARN, TAG, "%s,%d need todo", __FILE__, __LINE__)
#define ERR(...) log_log(LOG_ERROR, TAG, __VA_ARGS__)
#define FATAL(...)                        \
    log_log(LOG_FATAL, TAG, __VA_ARGS__); \
    do                                    \
    {                                     \
        LED_TOGGLE;                       \
        delay_ms(50);                     \
    } while (1)

#else

#define DBG(...)
#define INFO(...)
#define WARN(...)
#define ERR(...)
#define TODO(...)
#define FATAL(...)
#endif

const char *log_level_string(enum LOG_LEVEL level);
void log_set_level(enum LOG_LEVEL level);
void log_log(enum LOG_LEVEL level, const char *tag, const char *fmt, ...);
#endif
